package controllers;

import java.util.Date;
import java.util.List;

import models.ConstructionProject;
import models.ProjectVisualize;
import models.ProjectVisualizeReport;
import utils.YUtils;

public class ProjectVisualizeReports extends Application {
	
	public static void index(){
		List<ProjectVisualize> projectVisualizes = ProjectVisualize.findAll();
		String pVisualizes = ProjectVisualize.toSimpleJSON(projectVisualizes);
		
		String consProjects 
			=ConstructionProject.toSimpleJSON(ConstructionProject.findByDept(connectedUser().dept));
		render(pVisualizes,consProjects);
	}
	
	public static void json(int page,int pagesize){
		List<ProjectVisualizeReport> pvReports = 
				ProjectVisualizeReport.find("byBelongDept", connectedUser().dept).fetch(page, pagesize);
		long count = ProjectVisualizeReport.count("byBelongDept", connectedUser().dept);
		String pvReportsStr = ProjectVisualizeReport.toJSON(pvReports);
		String pvReportJson = YUtils.ligerGridData(pvReportsStr,count);
		renderJSON(pvReportJson);
	}
	
	public static void add(){
		ok();
	}
	
	public static void delete(long id){
		ProjectVisualizeReport.findById(id)._delete();
	}
	
	public static void search(Date searchDate){
		List<ProjectVisualizeReport> pvReports = 
				ProjectVisualizeReport.search(searchDate,connectedUser().dept);
		String pvReportsStr = ProjectVisualizeReport.toJSON(pvReports);
		String pvReportJson = YUtils.ligerGridData(pvReportsStr, pvReports.size());
		renderJSON(pvReportJson);
	}
	

}
